% Forecasts for monthly predictions
clear;clc;

load P00Data;
load Market;

h = 1; NW = 1; gam = 5;
for ct = 1:2 % Simple/Log returns
    if ct==1
        RM = CRSPSP_M - Rf_M; RF = Rf_M;  MktVar = MktStd(:,1).^2;
    else
        RM = log(1+CRSPSP_M) - log(1+Rf_M); RF = log(1+Rf_M); MktVar = MktStd(:,2).^2;
    end
    load ResultsFile Results;
    for i = 1:46
        if strcmp(VARS(i).Freq,'Monthly')
            TBeg = find(yyyymm==Results(i).SampleBeg);  TEnd = find(yyyymm==Results(i).SampleEnd); OOSBeg = find(yyyymm==Results(i).OOSBeg);
            if i==13 || i==17 % these are PLS variables
                XIS = VARS(i).DataIS{(ct-1)*4+1}; XOOS = VARS(i).DataOOS{(ct-1)*4+1};
            elseif i==22 % svix
                XIS = VARS(i).DataIS{1}; XOOS = VARS(i).DataOOS{1};
            else
                XIS = VARS(i).DataIS; XOOS = VARS(i).DataOOS;
            end
            XIS = (XIS - mean(XIS(TBeg:TEnd),'omitnan'))/std(XIS(TBeg:TEnd),'omitnan');

            Results(i).ISStats = IS(XIS, RM, TBeg, TEnd, h, NW);

            [Aols,Aivx,Wivx,WivxInd,Q,corrmat] = ivxlh(RM(TBeg:TEnd), XIS(TBeg:TEnd), h, 0);
            Results(i).ISStats.KMSSlope = Aivx; Results(i).ISStats.KMSp = Wivx(2);

            Results(i).OOSStats = OOS(XOOS, RM, RF, MktVar, h, TBeg, TEnd, OOSBeg, gam);
        end
    end % end loop i=1:45
    if ct==1
        Results_Simple_M = Results;
    else
        Results_Log_M = Results;
    end
end % end Simple/Log
save ResultsFile Results_* -append;
